package com.hanj.gulimall.coupon.controller;

import com.hanj.common.utils.PageUtils;
import com.hanj.common.utils.R;
import com.hanj.gulimall.coupon.entity.CouponEntity;
import com.hanj.gulimall.coupon.service.CouponService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * 优惠券信息
 *
 * @author hanj
 * @email hanj.cn @outlook.com
 * @date 2022 -01-14 21:35:26
 */
@RestController
@RequestMapping("/coupon/coupon")
public class CouponController {

    @Resource
    private CouponService couponService;

    /**
     * 列表
     *
     * @param params the params
     * @return the r
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {

        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     *
     * @param id the id
     * @return the r
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {

        CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     *
     * @param coupon the coupon
     * @return the r
     */
    @RequestMapping("/save")
    public R save(@RequestBody CouponEntity coupon) {

        couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     *
     * @param coupon the coupon
     * @return the r
     */
    @RequestMapping("/update")
    public R update(@RequestBody CouponEntity coupon) {

        couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     *
     * @param ids the ids
     * @return the r
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {

        couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
